package com.muchfish.reactor.api;

import reactor.core.publisher.Flux;
import java.time.Duration;

public class ReactorTimeoutExample {
    public static void main(String[] args) throws InterruptedException {
        Flux<Integer> source = Flux.just(1, 2, 3)
                .delayElements(Duration.ofSeconds(2)); // 模拟延迟

        // 在指定时间内等待数据流产生结果，否则触发超时
        source.timeout(Duration.ofSeconds(1))
                .subscribe(
                        data -> System.out.println("Received: " + data),
                        error -> System.err.println("Error: " + error),
                        () -> System.out.println("Done")
                );

        //睡一会，等待任务执行完成
        Thread.sleep(3333);
    }
}
